package com.ms.game.slot.base;

import java.util.ArrayList;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;

import com.ms.service.error.ErrorCode;

public class GameSeatVerifyManager {
	private ConcurrentHashMap<String, SeatVerifyInfo> verifymap = new ConcurrentHashMap<String, SeatVerifyInfo>();

	public ConcurrentHashMap<String, SeatVerifyInfo> getVerifyList() {
		return verifymap;
	}

	public void setVerifyList(ConcurrentHashMap<String, SeatVerifyInfo> verifyList) {
		this.verifymap = verifyList;
	}

	/**
	 * 讀取入座認證資訊
	 * 
	 * @param seatid
	 * @return
	 */
	public SeatVerifyInfo getVerifyInfo(String seatid) {
		if (!verifymap.containsKey(seatid)) {
			return null;
		}

		return verifymap.get(seatid);
	}

	/**
	 * 讀取入座過期資料
	 * 
	 * @return
	 */
	public ArrayList<SeatVerifyInfo> getTimeOut() {

		ArrayList<SeatVerifyInfo> list = new ArrayList<SeatVerifyInfo>();
		for (Entry<String, SeatVerifyInfo> entry : this.verifymap.entrySet()) {
			SeatVerifyInfo info = entry.getValue();
			if (info.isExpried()) {
				list.add(info);
			}
		}

		if (list.size() > 0) {
			for (SeatVerifyInfo info : list) {
				this.verifymap.remove(info.seatid);
			}
		}

		return list;
	}

	/**
	 * 此機台是否正在等待驗證
	 * 
	 * @param seatid
	 * @return
	 */
	public boolean isExist(String seatid) {
		if (!verifymap.containsKey(seatid)) {
			return false;
		}

		return true;
	}

	/**
	 * 新增機台
	 * 
	 * @param data
	 */
	public int add(SeatVerifyInfo data) {
		if (verifymap.containsKey(data.seatid)) {
		}

		verifymap.put(data.seatid, data);
		return ErrorCode.SUCCESS;
	}

	/**
	 * 移除資料
	 * 
	 * @param data
	 */
	public int remove(SeatVerifyInfo data) {
		if (!verifymap.containsKey(data.seatid)) {
		}

		this.verifymap.remove(data.seatid);
		return ErrorCode.SUCCESS;
	}
}
